home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / awksrc.zip / MSG.C < prev    next >
C/C++ Source or Header  |  1993-09-28  |  2KB  |  113 lines

  1. /*
  2.  * msg.c - routines for error messages
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991, 1992 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language.
  10.  * 
  11.  * GAWK is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  * 
  16.  * GAWK is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GAWK; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. #include "awk.h"
  27.  
  28. int sourceline = 0;
  29. char *source = NULL;
  30. #define _INTSIZEOF(n)     ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  31.  
  32. #define va_dcl va_list va_alist;
  33. #define va_start(ap) ap = (va_list)&va_alist
  34. #define va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  35. #define va_end(ap) ap = (va_list)0
  36.  
  37. /* VARARGS2 */
  38. void
  39. err(s, emsg, argp)
  40. char *s;
  41. char *emsg;
  42. va_list argp;
  43. {
  44.     char *file;
  45.  
  46.     (void) fflush(stdout);
  47.     (void) fprintf(stderr, "%s: ", myname);
  48.     if (sourceline) {
  49.         if (source)
  50.             (void) fprintf(stderr, "%s:", source);
  51.         else
  52.             (void) fprintf(stderr, "cmd. line:");
  53.  
  54.         (void) fprintf(stderr, "%d: ", sourceline);
  55.     }
  56.     if (FNR) {
  57.         file = FILENAME_node->var_value->stptr;
  58.         if (file)
  59.             (void) fprintf(stderr, "(FILENAME=%s ", file);
  60.         (void) fprintf(stderr, "FNR=%d) ", FNR);
  61.     }
  62.     (void) fprintf(stderr, s);
  63.     vfprintf(stderr, emsg, argp);
  64.     (void) fprintf(stderr, "\n");
  65.     (void) fflush(stderr);
  66. }
  67.  
  68. /*VARARGS0*/
  69. void
  70. msg(va_alist)
  71. va_dcl
  72. {
  73.     va_list args;
  74.     char *mesg;
  75.  
  76.     va_start(args);
  77.     mesg = va_arg(args, char *);
  78.     err("", mesg, args);
  79.     va_end(args);
  80. }
  81.  
  82. /*VARARGS0*/
  83. void
  84. warning(va_alist)
  85. va_dcl
  86. {
  87.     va_list args;
  88.     char *mesg;
  89.  
  90.     va_start(args);
  91.     mesg = va_arg(args, char *);
  92.     err("warning: ", mesg, args);
  93.     va_end(args);
  94. }
  95.  
  96. /*VARARGS0*/
  97. void
  98. fatal(va_alist)
  99. va_dcl
  100. {
  101.     va_list args;
  102.     char *mesg;
  103.  
  104.     va_start(args);
  105.     mesg = va_arg(args, char *);
  106.     err("fatal: ", mesg, args);
  107.     va_end(args);
  108. #ifdef DEBUG
  109.     abort();
  110. #endif
  111.     exit(2);
  112. }
  113.